package com.icesoft.xsnow.oauth.service;

import cn.hutool.core.util.ObjectUtil;
import lombok.AllArgsConstructor;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.token.ConsumerTokenServices;
import org.springframework.security.oauth2.provider.token.TokenStore;

/**
 * @program: xsnow
 * @description: 自定义删除TOKEN服务
 * @author: xuefeng.gao
 * @create: 2019-05-30 15:39
 **/
@AllArgsConstructor
public class ConsumerTokenServicesImpl implements ConsumerTokenServices {
    private TokenStore tokenStore;

    @Override
    public boolean revokeToken(String tokenValue) {
        OAuth2AccessToken accessToken = tokenStore.readAccessToken(tokenValue);
        if(ObjectUtil.isNotNull(accessToken)){
            tokenStore.removeAccessToken(accessToken);
            return true;
        }else{
            return false;
        }
    }
}
